

package com.hazelcast.replicatedmap.impl.operation;

import com.hazelcast.internal.util.scheduler.ScheduledEntry;
import com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore;
import com.hazelcast.spi.impl.operationservice.MutatingOperation;

import java.util.Collection;

/**
 * Evicts set of entries from the record store. Runs locally.
 */
public class EvictionOperation extends AbstractNamedSerializableOperation implements MutatingOperation {

    private ReplicatedRecordStore store;
    private Collection<ScheduledEntry<Object, Object>> entries;

    public EvictionOperation() {
    }

    public EvictionOperation(ReplicatedRecordStore store, Collection<ScheduledEntry<Object, Object>> entries) {
        this.store = store;
        this.entries = entries;
    }

    @Override
    public void run() throws Exception {
        for (ScheduledEntry<Object, Object> entry : entries) {
            Object key = entry.getKey();
            store.evict(key);
        }
    }

    @Override
    public boolean validatesTarget() {
        return false;
    }

    @Override
    public int getClassId() {
        return ReplicatedMapDataSerializerHook.EVICTION;
    }

    @Override
    public String getName() {
        return store.getName();
    }
}
